//
//  LZTopicVideoView.m
//  LZHundredJie
//
//  Created by apple on 16/4/15.
//  Copyright © 2016年 m14a.cn. All rights reserved.
//

#import "LZTopicVideoView.h"
#import "LZTopic.h"
#import "LZSeeBigPictureViewController.h"

@interface LZTopicVideoView ()

@property (weak, nonatomic) IBOutlet UILabel *playcountLabel;
@property (weak, nonatomic) IBOutlet UILabel *videotimeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation LZTopicVideoView

- (void)awakeFromNib
{
    // 取消自动伸缩
    self.autoresizingMask = UIViewAutoresizingNone;
    
    self.imageView.userInteractionEnabled = YES;
    [self.imageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(seeBigPicture)]];
}

/**
 *  查看大图
 */
// 这里把查看大图按钮的和用户交互给禁止调了,因为给后面的图片添加了手势,
// 这样点击整个图片区域都可以监听手势了,都会跳转界面
- (void)seeBigPicture
{
    LZSeeBigPictureViewController *seeBigVC = [[LZSeeBigPictureViewController alloc] init];
    // 顺传
    seeBigVC.topic = self.topic;
    // modal出来一个控制器
    [self.window.rootViewController presentViewController:seeBigVC animated:YES completion:nil];
}

- (void)setTopic:(LZTopic *)topic
{
    _topic = topic;
    _topic = topic;
    
    // 中间图片
    [self.imageView xmg_setImageWithOriginalImageURL:topic.image1 thumbnailImageURL:topic.image0];
    
    if (topic.playcount >= 10000) {
        self.playcountLabel.text = [NSString stringWithFormat:@"%.1f万播放", topic.playcount / 10000.0];
    } else {
        self.playcountLabel.text = [NSString stringWithFormat:@"%zd播放", topic.playcount];
    }
    // %02zd : 占据2位，多余的空位用0来填补
    self.videotimeLabel.text = [NSString stringWithFormat:@"%02zd:%02zd", topic.videotime / 60, topic.videotime % 60];
}

@end
